<?php

use yii\widgets\LinkPager;
use common\components\Word;
use yii\helpers\Url;

/* @var $this yii\web\View */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = '菜单管理';
$this->params['breadcrumbs'][] = $this->title;
?>
<hr/>
<div class="menu-index">

	<div style="margin-bottom: 10px">

		<a class="btn btn-success" href="<?= Url::to(['channel/create']) ?>">新增导航</a>

		<a class="btn btn-danger" href="javascript:GetCheckbox()">删除导航</a>

	</div>

	<div id="w0" class="grid-view">

		<div class="summary">
			第<b><?= $pages->offset + 1 ?>-<?= $pages->offset + count($list) ?></b>条，共<b><?= $pages->totalCount ?></b>条数据
		</div>

		<table class="table table-striped table-bordered">
			<thead>
			<tr>
				<th>
					<input type="checkbox" class="select-on-check-all" name="id_all" value="1">
				</th>
				<th>
					<a href="javascript:">
						ID
					</a>
				</th>
				<th>
					<a href="javascript:">
						标题
					</a>
				</th>
				<th>
					<a href="javascript:">
						URL
					</a>
				</th>
				<th>
					<a href="javascript:">
						排序
					</a>
				</th>

				<th>
					<a href="javascript:">
						创建时间
					</a>
				</th>
				<th>
					<a href="javascript:">
						状态
					</a>
				</th>
				<th>
					<a href="javascript:">
						操作
					</a>
				</th>
			</tr>
			</thead>

			<tbody>
			<?php foreach ($list as $val): ?>
				<tr>
					<td>
						<input type="checkbox" name="id[]" value="<?= $val->id ?>">
					</td>
					<td>
						<?= $val->id ?>
					</td>
					<td>
						<?= $val->title ?>
					</td>
					<td>
						<?= $val->url ?>
					</td>
					<td>
						<?= $val->sort ?>
					</td>

					<td>
						<?= Word::time_format($val->create_time) ?>
					</td>
					<td>
						<?= $val->status ? '<a type="button" class="btn btn-success btn-xs" role="button">正常</a>' : '<a type="button" class="btn btn-danger btn-xs" role="button">禁用</a>'  ?>
					</td>
					<td>
						<a href="<?= Url::to(['channel/update', 'id' => $val->id]) ?>" title="更新" data-pjax="0">
							<span class="glyphicon glyphicon-pencil"></span>
						</a>
						<a href="<?= Url::to(['channel/delete', 'id' => $val->id]) ?>" title="删除" data-confirm="您确定要删除此项吗？" data-method="post" data-pjax="0">
							<span class="glyphicon glyphicon-trash"></span>
						</a>
					</td>
				</tr>
			<?php endforeach ?>
			</tbody>
		</table>

		<?= LinkPager::widget([
			'pagination' => $pages
		]) ?>

	</div>

</div>

<script type="text/javascript">

	var GetCheckbox = function (){
		if(confirm('确定要删除吗？')) {
			var data = '';
			var list = $("input:checkbox[name='id[]']");

			for (var i = 0; i < list.length; i++) {
				if(list[i].checked){
					data += list[i].value + ',';
				}
			};
			if (data.length > 0) {
				$.post('<?= Url::to(['channel/delete']);?>', {id: data}, function (data) {
					location.href = '';
				});
			} else {
				alert("请选择要删除的关键字!");
			}
		}
	}

	<?php $this->beginBlock('js_end') ?>
	$(function(){
		highlight_subnav("<?= Url::to(['channel/index']) ?>");
	});
	<?php $this->endBlock() ?>
</script>
<?php $this->registerJs($this->blocks['js_end'], \yii\web\View::POS_END); ?>